package com.dc.project_java.test.lazy;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.dc.base.ui.activity.BaseVmVbActivity;
import com.dc.project_java.databinding.ActivityLazyBinding;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class LazyActivity extends BaseVmVbActivity<LazyViewModel, ActivityLazyBinding> {

    private List<Fragment> list = new ArrayList<>();
    private String[] title = {"Android", "iOS", "人工智能", "代码人生"};

    @Override
    protected void initView() {
        setTitle("Fragment懒加载使用示例");
        list.add(LazyFragment.newInstance("6809635626879549454"));
        list.add(LazyFragment.newInstance("6809635626661445640"));
        list.add(LazyFragment.newInstance("6809637773935378440"));
        list.add(LazyFragment.newInstance("6809637776263217160"));

        LazyFragmentPagerAdapter adapter = new LazyFragmentPagerAdapter(this, list);
        viewBinding.viewPager.setOffscreenPageLimit(list.size());
        for (int i = 0; i < title.length; i++) {
            viewBinding.tabLayout.addTab(viewBinding.tabLayout.newTab().setText(title[i]), i);
        }
        viewBinding.viewPager.setAdapter(adapter);
        new TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(title[position]);
            }
        }).attach();
    }

    @Override
    protected void initData() {

    }
}